package plugin.cs2java.actions;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import plugin.cs2java.utils.FileUtil;
import plugin.cs2java.utils.MessageUtil;
import plugin.cs2java.utils.StringUtil;

public class Cs2JavaAction extends AnAction {
    @Override
    public void actionPerformed(@NotNull AnActionEvent anActionEvent) {
        VirtualFile file = anActionEvent.getData(CommonDataKeys.VIRTUAL_FILE);
        if (file == null) {
            MessageUtil.show("请选择或打开文件！");
            return;
        }
        if (!MessageUtil.comfire(StringUtil.appendCenter(file.getName(), "确定修改?")))
            return;

        String text = FileUtil.getText(file);

        text = text.replace("{ get; set; }", ";")
                .replace(" List<string> ", " LinkedList<String> ")
                .replace(" virtual ", " ")
                .replace(" const ", " final ")
                .replace(" : Entity<int>", " extends EntityModel4Integer")
                .replace("    public class ", "@Data\r\npublic class ")
                .replace(" string ", " String ");

        FileUtil.setText(file, text);
        MessageUtil.show("修改完成！");
    }
}
